<?php
class App_Module_Media_Router_Http extends Mozg_Router_Router
{
	public function DetectCtrlAndAction(array $elements = array())
	{
		$ctrlName = $actionName = '';

		$styleExtensions = Mozg_Cfg::Get('global')->GetStyleExtensions();
        $mediaExtensions = Mozg_Cfg::Get('global')->GetMediaFilesExtensions();
         
        $path = $elements['path'];

        if (Mozg::Lib('Dir')->TestExtension($path, $styleExtensions))
        {
        	$ctrlName = 'style';
        }
        else if (Mozg::Lib('Dir')->TestExtension($path, $mediaExtensions))
        {
        	$ctrlName = 'image';
        }
        
		return array($ctrlName, $actionName);
	}

	/**
	 * определяем поведение controller & action
	 *
	 */
	public function Build(array &$elements = array())
	{
		$url = array();
		
		$url = array($elements['path']);
		unset($elements['path']);
		
		return $url;
	}
	
	public function Parse(array &$segments = array())
	{
		$elements = array();

        $elements['path'] = implode('/', array_map('urlencode', $segments));
        $segments = array();
        
		return $elements;
	}
}